package com.bnlr.lrparking.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.model.StallListBean;
import com.bnlr.lrparking.util.CustomLinearLayoutManager;

import java.util.List;

/**
 * @author tian
 * @date 2017/9/16
 */

public class StallDealAdapter extends BaseQuickAdapter<StallListBean.DataBean,BaseViewHolder>{

    private HotStallAdapter hotStallAdapter;
    public StallDealAdapter(@Nullable List<StallListBean.DataBean> data) {
        super(R.layout.item_stalldeal,data);
    }
    @Override
    protected void convert(BaseViewHolder holder, StallListBean.DataBean item) {
        holder.setIsRecyclable(false);
        ImageView iv = holder.getView(R.id.stall_deal_iv);
        RelativeLayout hotsale_adress = holder.getView(R.id.hotsale_adress);
        Glide.with(mContext).load(item.getPhotoUrl())
                .placeholder(R.mipmap.tab2_defaultgraph)
                .error(R.mipmap.tab2_defaultgraph)
                .into(iv);
        holder.setText(R.id.item_type,item.getStatus());
        holder.setText(R.id.tv_stalldeal_title,item.getTitle());
        holder.setText(R.id.tv_stalldeal_price,item.getPrice());

        if (item.getSpaceOwerType()==0){
            holder.setText(R.id.tv_stalldeal_type,"个人");
            // holder.setText(R.id.tv_stalldeal_address,item.getArea()+" |");
            //holder.setText(R.id.tv_stalldeal_size,item.getSize()+"㎡");
            holder.setText(R.id.tv_stall_num,"平台编号："+item.getCommonNumber());
        }else if (item.getSpaceOwerType()==1){
            holder.setText(R.id.tv_stalldeal_type,"开发商");
            holder.setText(R.id.tv_stall_num,"车位编号："+item.getNumber());
        }

        RecyclerView recycler_hotsale=holder.getView(R.id.recycler_hotsale);
        if (item.getDiscount().size()>0) {
            recycler_hotsale.setVisibility(View.VISIBLE);
            hotsale_adress.setVisibility(View.GONE);
            CustomLinearLayoutManager linearLayoutManager = new CustomLinearLayoutManager(mContext);
            linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
            linearLayoutManager.setScrollEnabled(false);
            recycler_hotsale.setLayoutManager(linearLayoutManager);
            hotStallAdapter = new HotStallAdapter(item.getDiscount());
            recycler_hotsale.setAdapter(hotStallAdapter);
        }else {
            recycler_hotsale.setVisibility(View.GONE);
            hotsale_adress.setVisibility(View.VISIBLE);
            holder.setText(R.id.tv_stalldeal_address_deilsa,item.getAddress());
        }
    }
}
